package org.mango.service.impl;

import org.mango.bean.User;
import org.mango.mapper.UserMapper;
import org.mango.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by meigang on 17/11/8.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void saveAndUpdateUser(User user) {
        //1.先查询数据库中有无该openid的用户
        if(userMapper.hasTheOpenId(user)>0){
            //2.如果有，则修改
            userMapper.updateByPrimaryKey(user);
        }else{
            //无则新增表示注册
            userMapper.insert(user);
        }
    }
}
